package com.example.literj.ui.main

import androidx.lifecycle.ViewModelProvider
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import com.example.literj.R
import com.example.literj.util.RxJavaTestUtil

class MainFragment : Fragment() {

    companion object {
        fun newInstance() = MainFragment()
    }

    private lateinit var viewModel: MainViewModel

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        viewModel = ViewModelProvider(this).get(MainViewModel::class.java)
        // TODO: Use the ViewModel
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        this.view?.findViewById<Button>(R.id.btnTest1)?.setOnClickListener {
            RxJavaTestUtil.sample1()
        }
        this.view?.findViewById<Button>(R.id.btnTest2)?.setOnClickListener {
            RxJavaTestUtil.sample2()
        }
        this.view?.findViewById<Button>(R.id.btnTest3)?.setOnClickListener {
            RxJavaTestUtil.sample3()
        }
        this.view?.findViewById<Button>(R.id.btnTest4)?.setOnClickListener {
            RxJavaTestUtil.sample4()
        }
    }

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        return inflater.inflate(R.layout.fragment_main, container, false)
    }

}